app.service('profitSettingService',['$http','$q','utilService',function($http,$q,utilService){

    this.findAll = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domainAgent + 'manage/profitSetting/findAll',
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.fetchByLevelAndType = function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domainAgent + 'manage/profitSetting/fetchByLevelAndType',
            params:{
                level: $scope.editData.level,
                type: $scope.editData.type
            }
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.update = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url: $scope.app.domainAgent + 'manage/profitSetting/update',
            data: {
                level: $scope.editData.level,
                type: $scope.editData.type,
                ratio: $scope.editData.ratio,
            },
            method: 'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}]);